﻿using System.Collections;
using UnityEngine;

namespace MassiveBattle.Controller.Boss
{
	public class BossController_10002 : BaseBossController
	{
		#region Attack Phase1
		private void Execute_Attack_Phase1()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST).GetTake(1, Query.ECount.TAUNT)))
				return;

			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST && Mathf.Abs(data.Pos - Target.Pos) <= 1).GetOrderBy(data => data == Target)))
				return;

			SetDamagePoint(SetDamagePoint_Attack_B);

			PlayTake_Attack_Source_Target();
		}
		#endregion

		#region Attack Phase2
		private void Execute_Attack_Phase2()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST).GetTake(1, Query.ECount.TAUNT)))
				return;

			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST && Mathf.Abs(data.Pos - Target.Pos) <= 1).GetOrderBy(data => data == Target)))
				return;

			SetDamagePoint(SetDamagePoint_Attack_B);

			PlayTake_Attack_Source_Target();
		}
		#endregion

		#region Skill Phase1
		private void Execute_Skill_Phase1()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST).GetTake(1, Query.ECount.TAUNT)))
				return;

			SetDamagePoint(SetDamagePoint_Skill_A);

			PlayTake_Skill_Source_Target_Camera();
		}

		private void event_01()
		{
			var target = Target;

			target.Damage(PointDic[target], true, this);

			Manager.StartCoroutine(SetStatCoroutine(target));
		}

		private IEnumerator SetStatCoroutine(BaseController target)
		{
			target.Stat.taunt.EventGet += ChangeTaunt;

			yield return new WaitForSeconds(10f);

			target.Stat.taunt.EventGet -= ChangeTaunt;
		}

		private void ChangeTaunt(ref int point)
		{
			point = 0;
		}
		#endregion

		#region Skill Phase2
		private int state = 0;

		private void Execute_Skill_Phase2()
		{
			if (!SetTarget(GetCandidate().GetOrderBy(data => Random.value).GetTake(4, Query.ECount.NONE)))
				return;

			SetDamagePoint(SetDamagePoint_Skill_A);

			state = 0;

			PlayTake_Skill_Source_Target_Camera();
		}

		private void event_02()
		{
			foreach (var target in TargetList)
				target.Damage(PointDic[target], true, this);
		}

		private void event_03()
		{
			if (state == 0)
				EventDamage += ChangeDamage;
			else if (state == 1)
				EventDamage -= ChangeDamage;

			state++;
		}

		private void ChangeDamage(ref int point)
		{
			point *= 2;
		}
		#endregion
	}
}
